package com.leoandroid.tool.toolsbox.pedometer;

import java.util.ArrayList;
import java.util.List;

public class PedometerManager {
    private List<PedometerObserver> observers = new ArrayList<>();
    private int count;

    private static PedometerManager instance;

    public static PedometerManager getInstance() {
        if (instance == null) {
            instance = new PedometerManager();
        }
        return instance;
    }

    public void notifyObserver(int count) {
        this.count = count;
        for (PedometerObserver observer : observers) {
            observer.onPedometerChanged(count);
        }
    }

    public void subscribe(PedometerObserver observer) {
        if (observer != null && !observers.contains(observer)) {
            observers.add(observer);
        }
    }

    public void unSubscribe(PedometerObserver observer) {
        if (observer != null) {
            observers.remove(observer);
        }
    }

    public int getCount() {
        return count;
    }
}
